/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import javax.sip.header.AllowEventsHeader;
import java.text.ParseException;

/**
 * This interface represents the AllowEvents SIP header, as defined by
 * <a href = "http://www.ietf.org/rfc/rfc3265.txt">RFC3265</a>, this header is
 * not part of RFC3261.
 * <p>
 * The AllowEventsHeader includes a list of tokens which indicates the event
 * packages supported by the client (if sent in a request) or server (if sent
 * in a response). In other words, a node sending an AllowEventsHeader is
 * advertising that it can process SUBSCRIBE requests and generate NOTIFY
 * requests for all of the event packages listed in that header.
 * <p>
 * Any node implementing one or more event packages SHOULD include an appropriate
 * AllowEventsHeader indicating all supported events in all methods which
 * initiate dialogs and their responses (such as INVITE) and OPTIONS responses.
 * This information is very useful, for example, in allowing user agents to
 * render particular interface elements appropriately according to whether the
 * events required to implement the features they represent are supported by
 * the appropriate nodes.
 * <p>
 * Note that "Allow-Events" headers MUST NOT be inserted by proxies.
 *
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class AllowEventsHeaderImpl extends HeaderBase implements AllowEventsHeader {
    private String eventType;

    private static final AllowEventsHeaderParser parser = new AllowEventsHeaderParser();

    public AllowEventsHeaderImpl() {
        super(AllowEventsHeader.NAME);
    }

    AllowEventsHeaderImpl(byte[] data, int start, int end) {
        super(AllowEventsHeader.NAME, data, start, end);
    }

    protected HeaderParser getParser() {
        return parser;
    }

    protected String getValueAsString() {
        return eventType;
    }

    /**
     * Sets the eventType defined in this AllowEventsHeader.
     *
     * @param eventType the String defining the method supported
     *                  in this AllowEventsHeader
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the Strings defining the eventType supported
     */
    public void setEventType(String eventType) throws ParseException {
        parse();
        this.eventType = eventType;
        invalidateHeaderData();
    }

    /**
     * Gets the eventType of the AllowEventsHeader.
     *
     * @return the String object identifing the eventTypes of AllowEventsHeader.
     */
    public String getEventType() {
        parse();
        return this.eventType;
    }

    /**
     * Creates and returns a deep copy of the Header. This methods must ensure a
     * deep copy of the Header, so that when a message is cloned the Header can
     * be modified without effecting the original Header in the message. This
     * provides useful functionality for proxying Requests and Responses, for
     * example:
     * <ul>
     * <li>Receive a message.
     * <li>Create a deep clone of the message and headers.
     * <li>Modify necessary headers.
     * <li>Proxy the message using the send methods on the SipProvider.
     * </ul>
     * This method overrides the clone method in java.lang.Object.
     *
     * @return a deep copy of Header
     */
    public Object clone() {
        final AllowEventsHeaderImpl header = new AllowEventsHeaderImpl();
        header.cloneBase(this);
        if (parsed) {
            header.eventType = this.eventType;
        }
        return header;
    }
}
/*
 * $Log$
 */